package net.wanho.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.po.Dept;
import net.wanho.service.DeptService;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2023-09-27
 */
@Api(tags = "部门表接口")
@RestController
@RequestMapping("/dept")
@RequiredArgsConstructor
public class DeptController {

    private final DeptService deptService;

    @ApiOperation("分页查询部门表")
    @GetMapping("/{pageNum}/{pageSize}")
    public AjaxResult findByPage(@ApiParam("当前页") @PathVariable int pageNum,@ApiParam("页大小") @PathVariable int pageSize, Dept dept){
        IPage page = deptService.findPage(pageNum,pageSize,dept);
        return AjaxResult.success(page);
    }

    @ApiOperation("按主键查询部门表")
    @GetMapping("/{id}")
    public AjaxResult getById(@ApiParam("学号") @PathVariable Serializable id){
        return AjaxResult.success(deptService.getById(id));
    }

    @ApiOperation("新增部门表")
    @PostMapping
    public AjaxResult add(@RequestBody Dept stu){
        deptService.save(stu);
        return AjaxResult.success();
    }

    @ApiOperation("修改部门表")
    @PutMapping
    public AjaxResult edit(@RequestBody Dept dept){
        deptService.updateById(dept);
        return AjaxResult.success();
    }

    @ApiOperation("按主键删除部门表")
    @DeleteMapping("/{id}")
    public AjaxResult removeById(@ApiParam("学号") @PathVariable Serializable id){
        deptService.removeById(id);
        return AjaxResult.success();
    }
}
